<!doctype html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<body>
	<section class="content-header">
		<h1>
			部门 <small th:text="(${department.new}?'新建':'编辑')+'部门'"></small>
		</h1>
		<ol class="breadcrumb">
			<li>
				<a th:href="@{/dashboard}"><i class="fa fa-dashboard"></i> 首页</a>
			</li>
			<li>
				<a href="javascript:;">系统管理</a>
			</li>
			<li class="active" th:text="(${department.new}?'新建':'编辑')+'部门'"></li>
		</ol>
	</section>

	<section class="content">
		<div class="box box-primary">
			<div class="box-header with-border">
				<h3 class="box-title">请输入部门信息</h3>
			</div>
			<form id="form-department" class="form-horizontal" th:action="@{/department/save}" method="post"
				th:object="${department}">
				<input type="hidden" name="id" th:value="*{id}" />
				<div class="box-body">
					<div class="form-group" th:if="*{parent}!=null">
						<label for="input-parent-name" class="col-sm-2 control-label">上级部门</label>

						<div class="col-sm-10">
							<input class="form-control" readonly="readonly" id="input-parent-name" th:value="*{parent.name}"> <input
								name="parent" type="hidden" th:value="*{parent.id}">
						</div>
					</div>

					<div class="form-group">
						<label for="input-name" class="col-sm-2 control-label">名称</label>

						<div class="col-sm-10">
							<input class="form-control" id="input-name" name="name" th:value="*{name}" placeholder="请输入名称" type="text"
								data-bv-notempty="true" data-bv-notempty-message="请填写名称">
						</div>
					</div>

					<div class="form-group">
						<label for="input-phone" class="col-sm-2 control-label">部门电话</label>

						<div class="col-sm-10">
							<input class="form-control" id="input-phone" name="phone" th:value="*{phone}" placeholder="请输入部门电话" type="text">
						</div>
					</div>

					<div class="form-group">
						<label for="input-sortNo" class="col-sm-2 control-label">排序号</label>

						<div class="col-sm-10">
							<input class="form-control" id="input-sortNo" name="sortNo" th:value="*{sortNo}" placeholder="请输入排序号"
								type="number">
						</div>
					</div>
				</div>
				<div class="box-footer">
					<button type="button" class="btn btn-default" onclick="location.href='#/page/department'">返回列表</button>
					<button type="submit" class="btn btn-success pull-right">保存</button>
				</div>
			</form>
		</div>
	</section>


	<script type="text/javascript">
		requirejs([ "domReady", "validator" ], function(ready) {
			ready(function() {
				activeMenu("system_department");
				$("#form-department").bootstrapValidator().on("success.form.bv", function(e) {
					e.preventDefault();
					var $form = $(e.target);
					var bv = $form.data('bootstrapValidator');
					$.post($form.attr('action'), $form.serialize(), function(result) {
						if (result.success) {
							$.alert({
								title : false,
								content : "保存成功",
								buttons : {
									ok : {
										text : "返回列表",
										action : function() {
											location.href = "#/page/department";
										}
									}
								}
							});
						} else {
							$.alert({
								title : false,
								content : result.msg
							});
							$form.bootstrapValidator('disableSubmitButtons', false);
						}
					}, "json");
				});
			});
		});
	</script>
</body>
</html>

